/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sree.tali.dao.homepage.impl;

import com.sree.tali.hibernate.pojo.ArticleNumber;
import com.sree.tali.pojo.UploadImagePojo;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author sreenuv
 */
public class AdminDao implements IAdminDao {
     public  void save( UploadImagePojo localAdminHomepojo, Session paramSession)
     {
         try{
      Transaction localTransaction = paramSession.beginTransaction();
      paramSession.save(localAdminHomepojo);
      localTransaction.commit();
         }
         catch(Exception e)
         {
             e.printStackTrace();
         }
         finally
         {
             if(paramSession!=null)
                 paramSession.close();
         }
    }
      public  int getArticleNumber(Session paramSession)
     {
      int articleNumber = 0;
      String qry="from ArticleNumber";
      Query query = paramSession.createQuery(qry);
      try{
      List<ArticleNumber> list  = query.list();
      Transaction localTransaction = paramSession.beginTransaction();
      if(list==null||list.size()==0)
      {
           ArticleNumber article = new ArticleNumber();
           article.setArticleNumber(1);
           paramSession.save(article);
           articleNumber = 1;
      }
      else
      {
           ArticleNumber article =list.get(0);
           articleNumber = article.getArticleNumber();
           article.setArticleNumber(articleNumber+1);
           paramSession.update(article);
      }
      localTransaction.commit();
     }
        catch(Exception e)
         {
             e.printStackTrace();
         }
         finally
         {
             if(paramSession!=null)
                 paramSession.close();
         }
      return articleNumber;
    }
}
